package com.example.queryweatherdemo;


import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;


public class GsonUtil {
    private static final Gson mGson=new Gson();
    public static RealtimeModel  realtimeWeather(String jsonStr){
        WeatherObj<TimeObj> weatherObj=mGson.fromJson(jsonStr,WeatherObj.class);
        String jsonResult=mGson.toJson(weatherObj.getResult());

        TimeObj<RealtimeModel> result=mGson.fromJson(jsonResult,TimeObj.class);
        return result.getRealtime();

    }

    public static FutureModel[] futureWeather(String jsonStr){

        WeatherObj<TimeObj> weatherObj=mGson.fromJson(jsonStr,WeatherObj.class);
        String jsonResult=mGson.toJson(weatherObj.getResult());

        Type type=new TypeToken<TimeObj<FutureModel>>(){}.getType();
        TimeObj<FutureModel> result=mGson.fromJson(jsonResult,type);


        return result.getFuture();
    }

}
